package com.lagou.edu.spring.web;

import com.lagou.edu.spring.exceptions.MySpringException;

import java.util.HashMap;
import java.util.Map;

/**
 * 配置方式类型
 *
 * @author 大犬
 * @date 2020/4/2
 */
public enum WebConfigTypeEnum {
    /**
     * 配置类方式
     */
    CONFIG_CLASS("configClass", "配置类"),

    CONFIG_FILE("configFile", "配置文件"),

    CONFIG_PACKAGE("configPackage", "使用包路径"),

    ;
    private String value;

    private String desc;

    WebConfigTypeEnum(String value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    private static final Map<String, WebConfigTypeEnum> TYPE_MAP;

    static {
        TYPE_MAP = new HashMap<>(WebConfigTypeEnum.values().length);
        for (WebConfigTypeEnum configTypeEnum : WebConfigTypeEnum.values()) {
            TYPE_MAP.put(configTypeEnum.value, configTypeEnum);
        }
    }

    public static WebConfigTypeEnum getByValue(String value) {
        WebConfigTypeEnum typeEnum = TYPE_MAP.get(value);
        if (typeEnum == null) {
            throw new MySpringException("not supported this config type:" + value);
        }
        return typeEnum;
    }
}
